#!/bin/sh
##################################
# complie and install redis on linux(redhat)
# 1.download redis source from websire:http://redis.io/download,current stable version:2.8.19
#	wget http://download.redis.io/redis-stable.tar.gz
# 2.unzip redis tarball
#   tar zxvf redis-stable.tar.gz
# 3.complie redis
#	cd  redis-stable
#	make
# 4. install redis
#	make install (default install_path:/usr/local/bin,if change install path,use:make PREFIX=/some/other/directory install)
# 5.copy configure file to /etc/redis.conf
#	cp ./redis.conf /etc/redis.conf
# redis version:
# 2015-03-17
# budingge.com
##################################

intall_path="/usr/local/bin/"
if [ ! -w "$intall_path" ]; then 
echo "ERROR, no write permission on $intall_path for redis";
exit 1
fi 
if [ ! -w "/etc/" ]; then 
echo "ERROR, no write permission on /etc/ for redis";
exit 1
fi 

echo 'download last stable redis ...'
wget http://download.redis.io/redis-stable.tar.gz
if [ $? != 0 ]; then
echo "ERROR, failed download redis";
exit 1
fi
echo 'finished downloaded redis ...'

echo 'untar redis tarball'
tar zxvf redis-stable.tar.gz
if [ $? != 0 ]; then
echo "ERROR, failed untar redis tarball";
exit 1
fi


echo 'cd redis-stable directory'
cd redis-stable
if [ $? != 0 ]; then
echo "ERROR, failed cd redis-stable directory";
exit 1
fi

# make
echo 'starting compile redis ...'
make

if [ $? != 0 ]; then
echo "ERROR, failed compile redis";
exit 1
fi

#make install
echo 'starting install redis ...'
make install
if [ $? != 0 ]; then
echo "ERROR, failed install redis";
exit 1
fi

#copy configure file
if [ ! -f "/etc/redis.conf" ]; then 
	cp ./redis.conf /etc/redis.conf
fi

echo 'finished install redis, have fun!'
